<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title>OAuth2 Server</title>
</head>
<body>

<shiro:guest>
    游客你好，请<a href="<c:url value="/login"/>">登录</a>！
</shiro:guest>

<shiro:user>
	欢迎[<shiro:principal/>]，点击<a href="<c:url value="/logout"/>">退出</a>！<br/>
    <hr/>
   	标题&nbsp;<input id="title" name="title"><br/>
   	内容&nbsp;<textarea id="content" rows="5" cols="50" name="content"></textarea><br/>
   	<button id="addNote">添加笔记</button>
    <hr/>
    <button id="listNote">查看笔记</button><br/>
    <hr/>
   	操作结果:<br/>
    <textarea id="notes" rows="20" cols="100" readonly="readonly"></textarea>
</shiro:user>

	<input id="ctx" type="hidden" value="<c:url value="/"/>"> 
    <script type="text/javascript" src="<c:url value="/static/js/jquery-1.11.0.min.js"/>"></script>
    <script type="text/javascript">
    	var ctx = $("#ctx").val();
    	$("#addNote").click(function(){
    		$.ajax({
    			url:ctx+"res/addNote",
    			type:"POST",
    			data:{
    				title:$("#title").val(),
    				content:$("#content").val()
    			},
    			dataType:"json",
    			success:function(result){
    				var data = result && result.data;
    				var msg = result && result.msg;
    				$("#notes").val((data && JSON.stringify(data, null, 4)) || (msg||"程序异常"));
    			}
    			
    		});
    		return ;
    	});
    	$("#listNote").click(function(){
    		$.ajax({
    			url:ctx+"res/note",
    			dataType:"json",
    			success:function(result){
    				var data = result && result.data;
    				var msg = result && result.msg;
    				$("#notes").val((data && JSON.stringify(data, null, 4)) || (msg||"程序异常"));
    			}    			
    		});
    	});
    </script>
</body>
</html>